<template>
  <!-- 启动页 -->
  <view :style="{ width: width, height: height }">
    <image
      :style="{ width: width, height: height }"
      mode="aspectFill"
      class="start"
      src="@/static/image/start/start.png"
    ></image>
  </view>
</template>

<script>
export default {
  data() {
    return {
      width: 375,
      height: 778,
    };
  },
  mounted() {
    //
    let { errMsg, safeArea, statusBarHeight } = uni.getSystemInfoSync();

    if (errMsg === 'getSystemInfoSync:ok') {
      this.width = safeArea.width;
      //高度
      this.height = safeArea.height + statusBarHeight;
    }
    setTimeout(() => {
      if (!!uni.getStorageSync('token')) {
        // 初始化
        this.init();
      } else {
        uni.reLaunch({
          url: '/pages/main/login/login',
        });
      }
    }, 3000);
  },
  methods: {
    init() {
      // 工人
      if (uni.getStorageSync('login_role') === 'worker') {
        //跳转工人首页
        uni.reLaunch({
          url: '/pages/worker-home/worker-home',
        });
      } else if (uni.getStorageSync('login_role') === 'staff') {
        uni.$zx.user_api.getUserInfo().then((data) => {
          // uni.setStorageSync("user_info", JSON.stringify(data));
          uni.setStorageSync('permissions', data.permissions);
        });
        //跳转员工首页
        uni.reLaunch({
          url: '/pages/staff-home/staff-home',
        });
      } else {
        uni.reLaunch({
          url: '/pages/main/login/login',
        });
      }
    },
  },
};
</script>

<style scoped>
.start {
  width: 375px;
  height: 778px;
}
</style>
